function deploy_vhd (
	[int] $scenario,  #scenario 0..#s-1
	[int] $computer #ordinateur 0..#c-1
) { 
	$VMServer = $CONFIG_SERVERS[$computer]
	$sujet = $sujets[$scenario]
	
	
	write-host ("directory loaded from config\repertoires.ps1: "+$CONFIG_CLIENT_VM_STORAGE_DIR) -foregroundcolor yellow
	
	foreach($vm in $sujet.vms) {
		(banner($vm.name)) | write-host -foregroundcolor yellow
		$remote_dir = "\\"+$VMServer+$CONFIG_CLIENT_VM_STORAGE_DIR+$sujet.scenario_name+"\"+$vm.name+"\";
		
		if( (-NOT ($vm.vfd)) -AND (-NOT($vm.vhd_and_iso[0])) -AND (-NOT($vm.vhd_and_iso[1])) -AND (-NOT($vm.vhd_and_iso[2])) -AND (-NOT($vm.vhd_and_iso[3]))  ) {
			write-host ("ERROR: no VHD nor VFD nor ISO were defined for the VM: "+($sujet.scenario_name)+($vm.name)+". Please check config\scenarios\"+($scenario+1)+".ps1") -foregroundcolor red
		} else {
			
			foreach($disk_type in @("vfd";"vhd_and_iso[0]";"vhd_and_iso[1]";"vhd_and_iso[2]";"vhd_and_iso[3]")) {
				invoke-expression('if($disk_type -eq "vfd") { $exists = $vm.'+$disk_type+' } else { if($vm.vhd_and_iso) { $exists =  $vm.'+$disk_type+' } else { $exists = $FALSE } }')
				if($exists) {
					$arr = $exists.split("\");
					$local_dir = ""
					for($i=1;$i -lt $arr.length;$i++) {
						$local_dir += $arr[$i-1]+"\"
					}
					if($arr.length -ne 0) {
						$local_filename = $arr[$arr.length-1]
						
						$remote_filename = $local_filename
						$remote_vhd = $remote_dir+$remote_filename
						
						
						
						write-host "Checking for $remote_vhd file existence"
						if(test-path $remote_vhd) {
						
							write-host ("ERROR: the "+$disk_type+" already exist") -foregroundcolor red
							do {
								write-host  ("DELETE the remote "+$disk_type+"? [y/n]") -foregroundcolor yellow
								if(Host-IsInactiveForSeconds 10) {
									$snap = "n"
								} else {
									$snap = read-host -prompt "?"
								}
							} while( $snap.CompareTo("y") -AND $snap.CompareTo("n"))

							if(!$snap.CompareTo("y")) {
							do {
								write-host "Are you SURE? [y/n]" -foregroundcolor yellow
								if(Host-IsInactiveForSeconds 10){
									$sure = "n"
								} else {
									$sure = read-host -prompt "?"
								}
							} while($sure.CompareTo("y") -AND $sure.CompareTo("n"))
							if(!$sure.CompareTo("n")) { $snap = "n" }
							}
							if($snap -eq "y") {
								remove-item $remote_vhd
							}
						}
						
						#if the remote file does not exist
						if( -NOT (test-path $remote_vhd)) {
							$local_dir2 = $local_dir
							$remote_dir2 = $remote_dir
							if($local_dir2.substring($local_dir2.length-1,1) -eq "\") { $local_dir2 = $local_dir2.substring(0,$local_dir2.length-1) }
							if($remote_dir2.substring($remote_dir2.length-1,1) -eq "\") { $remote_dir2 = $remote_dir2.substring(0,$remote_dir2.length-1) }
							
							$command = "robocopy " + [char]34 + $local_dir2+ [char]34+ " "+ [char]34+ $remote_dir2+ [char]34+" "+[char]34+$local_filename+[char]34+" /eta"
							write-host $command -foregroundcolor yellow
							
							invoke-expression $command
						}
					} else {
						write-host (" WARNING: no "+$disk_type+" specified. It will not be mounted.") -foregroundcolor pink
					}
				} else {
					write-host ("NO "+$disk_type+" created. You did not specify any") -foregroundcolor red
				}
			}
		}
	}
}

$actions.Insert($actions.Count,"deploy_vhd");
set-variable LANG_ACTION__DEPLOY_VHD "DEPLOYER les VHD,VFD,ISO" -scope global
